package com.ruoyi.web.controller.placeType;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.place_type.domain.PlaceType;
import com.ruoyi.place_type.service.IPlaceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 场所类型Controller
 * 
 * @author 张富饶
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/place_type/place_type")
public class PlaceTypeController extends BaseController
{
    @Autowired
    private IPlaceTypeService placeTypeService;

    /**
     * 查询场所类型列表
     */
    @PreAuthorize("@ss.hasPermi('place_type:place_type:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlaceType placeType)
    {
        startPage();
        List<PlaceType> list = placeTypeService.selectPlaceTypeList(placeType);
        return getDataTable(list);
    }

    /**
     * 导出场所类型列表
     */
    @PreAuthorize("@ss.hasPermi('place_type:place_type:export')")
    @Log(title = "场所类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlaceType placeType)
    {
        List<PlaceType> list = placeTypeService.selectPlaceTypeList(placeType);
        ExcelUtil<PlaceType> util = new ExcelUtil<PlaceType>(PlaceType.class);
        util.exportExcel(response, list, "场所类型数据");
    }

    /**
     * 获取场所类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('place_type:place_type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(placeTypeService.selectPlaceTypeById(id));
    }

    /**
     * 新增场所类型
     */
    @PreAuthorize("@ss.hasPermi('place_type:place_type:add')")
    @Log(title = "场所类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlaceType placeType)
    {
        return toAjax(placeTypeService.insertPlaceType(placeType));
    }

    /**
     * 修改场所类型
     */
    @PreAuthorize("@ss.hasPermi('place_type:place_type:edit')")
    @Log(title = "场所类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlaceType placeType)
    {
        return toAjax(placeTypeService.updatePlaceType(placeType));
    }

    /**
     * 删除场所类型
     */
    @PreAuthorize("@ss.hasPermi('place_type:place_type:remove')")
    @Log(title = "场所类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(placeTypeService.deletePlaceTypeByIds(ids));
    }
}
